package com.example.mall.web.controller;

import com.example.mall.domain.PerformanceLogs;
import com.example.mall.dto.PerformanceLogsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PerformanceLogsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPerformanceLogsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/performanceLogs")
public class PerformanceLogsController {

    @Autowired
    public IPerformanceLogsService performanceLogsService;

    /**
     * 分页查询性能日志表信息
     * @param performanceLogsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询性能日志表信息",notes = "分页查询性能日志表信息",httpMethod = "GET")
    public JSONResult queryPage(PerformanceLogsQuery performanceLogsQuery){
        PageDTO<PerformanceLogsDto> performanceLogsPageDTO = performanceLogsService.queryPage(performanceLogsQuery);
        return JSONResult.success("查询成功",performanceLogsPageDTO);
    }

    /**
     * 根据id查询性能日志表信息
     * @param performanceId
     * @return
     */
    @GetMapping("query/{performanceId}")
    @ApiOperation(value = "根据id查询性能日志表信息",notes = "根据id查询性能日志表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("performanceId")Long performanceId){
        //1.根据id查询用户信息
        if (performanceId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PERFORMANCEID_NOT_ID);
        }
        PerformanceLogs performanceLogs = performanceLogsService.getById(performanceId);
        return JSONResult.success("查询成功",performanceLogs);
    }

    /**
     * 根据id查询性能日志表信息
     * @param performanceId
     * @return
     */
    @GetMapping("queryPerformanceLogsById/{performanceId}")
    @ApiOperation(value = "根据id查询性能日志表信息",notes = "根据id查询性能日志表信息",httpMethod = "GET")
    public JSONResult queryPerformanceLogsById(@PathVariable("performanceId")Long performanceId){
        //1.根据id查询用户信息
        if (performanceId == null){
            throw new GlobalCustomerException(ErrorEnumCode.PERFORMANCEID_NOT_ID);
        }
        PerformanceLogs performanceLogs = performanceLogsService.queryPerformanceLogsById(performanceId);
        return JSONResult.success("查询成功",performanceLogs);
    }

    /**
     * 查询全部性能日志表信息
     * @param
     * @return
     */
    @GetMapping("queryPerformanceLogsList")
    @ApiOperation(value = "查询全部性能日志表信息",notes = "查询全部性能日志表信息",httpMethod = "GET")
    public JSONResult queryPerformanceLogsList(){
        List<PerformanceLogs> performanceLogs = performanceLogsService.queryPerformanceLogsList();
        return JSONResult.success("查询成功",performanceLogs);
    }

    /**
     * 新增性能日志表
     * @param performanceLogsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增性能日志表",notes = "新增性能日志表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PerformanceLogsDto performanceLogsDto){
        performanceLogsService.insert(performanceLogsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改性能日志表信息
     * @param performanceLogsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改性能日志表信息",notes = "修改性能日志表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PerformanceLogsDto performanceLogsDto){
        performanceLogsService.update(performanceLogsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除性能日志表信息
     * @param performanceId
     * @return
     */
    @PostMapping("delete/{performanceId}")
    @ApiOperation(value = "删除性能日志表信息",notes = "删除性能日志表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("performanceId") Long performanceId) {
        performanceLogsService.delete(performanceId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除性能日志表信息
     * @param performanceIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除性能日志表信息",notes = "批量删除性能日志表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> performanceIds) {
        performanceLogsService.deleteBatch(performanceIds);
        return JSONResult.success("批量删除成功");
    }
}
